/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;

/**
 *Class for the Ultrasonic
 * @author Max
 */
public class SonicSensor
{

    final int portNo = 1;
    UltrasonicSensor sonic;
    int currentValue;
    final int minDistance = 25;

    /**
     * Creates an object
     */
    public SonicSensor()
    {
        sonic = new UltrasonicSensor(SensorPort.PORTS[portNo]);
        currentValue = -1;
    }

    /**
     * Calculates the distance between sensor and object and stores the value
     */
    public void calcDistance()
    {
        currentValue = sonic.getDistance();
        //modes.ModeController.dm.echo("Sonic: "+currentValue);
    }

    /**
     *
     * @return true if distance less than minDistance
     */
    public boolean isObject()
    {
        calcDistance();
        if (getCurrentValue() < minDistance)
        {
            return true;
        }
        return false;
    }

    /**
     *
     * @return current value
     */
    public int getCurrentValue()
    {
        return currentValue;
    }
}
